/**
 * @description service的统一出口
 * @author 盘古他爹
 */

import LSRequest from "./request"
import CacheLocal from "@/utils/cacheLocal"
import { BASE_URL, TIME_OUT } from "./request/config"
import { ElMessage } from "element-plus"
import { ElLoading } from "element-plus"
const lsRequest = new LSRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT,
  // loadingInstance: {},
  interceptors: {
    requestInterceptor: (config) => {
      console.log("请求成功的拦截555", config)
      // this.loadingInstance
      if (!(config.url === "/user/login" || config.url === "/user/register")) {
        const token = CacheLocal.getItem("LSToken")

        if (token) {
          config.headers!.Authorization = `Bearer ${token}`
        }
      }
      return config
    },
    requestInterceptorCatch: (err) => {
      console.log("失败了：", err)
    },
    responseInterceptor: (config) => {
      if (!config.data.success) {
        ElMessage.error(config.data.msg)
      }

      return config.data
    },
    responseInterceptorCatch: (err) => err
  }
})

export const lsRequest22 = new LSRequest({
  baseURL: BASE_URL,
  timeout: TIME_OUT
})

export default lsRequest
